package com.example.administrator.officeplatform.Audit;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.bean.ReimbursementVoInfo;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/12/14.
 */

public class AuditAdapter extends RecyclerView.Adapter{
    public static interface OnRecyclerViewListener {
        void onItemClick(int position);

        boolean onItemLongClick(int position);
    }

    private OnRecyclerViewListener onRecyclerViewListener;

    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    private List<ReimbursementVoInfo> list = new ArrayList<>();
    private Context mContext;

    public AuditAdapter(List<ReimbursementVoInfo> list, Context mContext) {
        this.list = list;
        this.mContext=mContext;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_audit, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final PersonViewHolder personViewHolder = (PersonViewHolder) holder;
        personViewHolder.position = position;
        ReimbursementVoInfo reimbursementVoInfo= list.get(position);
        DecimalFormat format = new DecimalFormat("0.00");


        personViewHolder.tv_bxr.setText("申请人:"+reimbursementVoInfo.getProposer());
        personViewHolder.tv_bxbm.setText("报销部门:"+reimbursementVoInfo.getDepartmentName());
//        personViewHolder.tv_bxxm.setText("报销项目:"+reimbursementVoInfo.getCostProject());
        personViewHolder.tv_money.setText("金额:￥"+format.format(reimbursementVoInfo.getMoney()));
        personViewHolder.tv_date.setText("报销日期:"+reimbursementVoInfo.getReimbursementDate());
        personViewHolder.tv_dh.setText("报销单号:"+reimbursementVoInfo.getReimbursementCode());
        if(reimbursementVoInfo.getMyState()==2){
            personViewHolder.tv_zt.setText("状态:已审核");
        }else if(reimbursementVoInfo.getMyState()==1){
            personViewHolder.tv_zt.setText("状态:待审核");
        }else if(reimbursementVoInfo.getMyState()==3){
            personViewHolder.tv_zt.setText("状态:驳回");
        }


    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public int position;
        public TextView tv_bxr,tv_bxbm,tv_bxxm,tv_money,tv_dh,tv_zt,tv_date;

        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_bxr = (TextView)itemView.findViewById(R.id.tv_bxr);
            tv_bxbm = (TextView)itemView.findViewById(R.id.tv_bxbm);
            tv_bxxm = (TextView)itemView.findViewById(R.id.tv_bxxm);
            tv_money = (TextView)itemView.findViewById(R.id.tv_money);
            tv_dh = (TextView)itemView.findViewById(R.id.tv_dh);
            tv_zt = (TextView)itemView.findViewById(R.id.tv_zt);
            tv_date= (TextView)itemView.findViewById(R.id.tv_date);

            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }

        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}
